package paulsnet;

import com.jme3.network.Client;
import com.jme3.network.Network;
import com.jme3.network.serializing.Serializer;
import com.simsilica.es.EntitySet;
import com.simsilica.es.client.RemoteEntityData;
import com.simsilica.es.net.EntitySerializers;

/**
 *
 * @author eike
 */
public class MyClient {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Client c;
        EntitySet es;
        RemoteEntityData red = null;

        float tpu = 0;
        try {
            EntitySerializers.initialize();
            Serializer.registerClass(TestComponent.class);
            c = Network.connectToServer("localhost", 1235);
            c.start();
            red = new RemoteEntityData(c, 0);
            Thread.sleep(100);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            System.exit(1);
        }
        es = red.getEntities(TestComponent.class);

        float last = 0, tpf, now;

        while (true) {
            now = (float) System.nanoTime() / 1000000000f;
            tpf = now - last;
            last = now;
            tpu += tpf;
            if (es.applyChanges()) {
                System.out.println(tpu);
                tpu = 0;
            }
            try {
                Thread.sleep(1);
            } catch (Exception e) {
            }
        }
    }
}
